package cn.edu.zhku.citrusmonitor.person.expert.service;

import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;

import cn.edu.zhku.citrusmonitor.domain.TbExpert;
import cn.edu.zhku.citrusmonitor.domain.TbUser;
import cn.edu.zhku.citrusmonitor.person.expert.dao.ExpertDao;
import cn.edu.zhku.citrusmonitor.person.expert.dao.ExpertDaoImpl;

public class ExpertServiceImpl implements ExpertService {
	ExpertDao ed=new ExpertDaoImpl();
	/**
	 * 通过专家名查找
	 */
	@Override
	public Object searchByExpertName(String expertName) {
		// TODO Auto-generated method stub
		try {
			return ed.getUserByExpertName(expertName);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
	/**
	 * 通过专家名和密码获得对象
	 */
	@Override
	public TbExpert login(String expertName, String password) {
		// TODO Auto-generated method stub
		try {
			return ed.getUserByExpertNameAndPwd(expertName,password);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * 添加账号
	 */
	@Override
	public int addExpert(TbExpert expert) {
		// TODO Auto-generated method stub
		try {
			return ed.addExpertByBean(expert);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}
	}
	/**
	 * 修改信息
	 */
	@Override
	public int modifyExpert(TbExpert expert) {
		try {
			return ed.modify(expert);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}
	}
	/**
	 * 删除
	 */
	@Override
	public int deleteExpert(String id) {
		// TODO Auto-generated method stub
		try {
			return ed.deleteExpertById(id);
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}
	}
	/**
	 * 根据id获取用户
	 */
	
	@Override
	public TbExpert getExpert(String id) {
		// TODO Auto-generated method stub
		try {
			return ed.getExpertById(id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	/**
	 * 获取总记录数
	 */
	@Override
	public long getTotalCounts() {
		// TODO Auto-generated method stub
		try {
			return ed.getTotal();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}
	}
	/**
	 * 获得对象集合
	 */
	@Override
	public List<TbExpert> getBeanList(int currentPage, long pageSize) {
		// TODO Auto-generated method stub
		try {
			return ed.getList(currentPage,pageSize);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}
	@Override
	public TbExpert getExpertByName(String name) {
		// TODO Auto-generated method stub
		try {
			return ed.getExpertByName(name);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
		
	}
	@Override
	public int removeAll(String[] ids) {
		// TODO Auto-generated method stub
		try {
			int count=0;
			int[] values=ed.removeAllById(ids);
			//System.out.println(Arrays.toString(values));
			for(int i:values) {
				count+=i;
			}
			return count;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}

}
